AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )

function ENT:Initialize()
	self.Entity:SetModel( "models/dav0r/hoverball.mdl" )
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetSolid( SOLID_VPHYSICS )
	self.Entity:SetMaterial("models/drew/submass")
	self.incrad = false
	local phys = self.Entity:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
		phys:SetMass(150
		)
	end
	self.Entity:SetColor(255,255,255,254) --hack to show the glow
	local Sprite = ents.Create("env_sprite");
	Sprite:SetPos(self.Entity:GetPos())
	Sprite:SetKeyValue( "renderfx", "15" )
	Sprite:SetKeyValue( "model", "sprites/glow02.vmt")
	Sprite:SetKeyValue( "scale", "1")
	Sprite:SetKeyValue( "spawnflags", "1")
	Sprite:SetKeyValue( "angles", "0 0 0")
	Sprite:SetKeyValue( "rendermode", "9")
	Sprite:SetKeyValue( "renderamt", "255")
	Sprite:SetKeyValue( "rendercolor", "100 240 100")
	Sprite:Spawn()
	Sprite:Activate()
	Sprite:SetParent(self.Entity)
end

function ENT:Think()
	if self.incrad then
		local dam = math.random(4,10)
		local b = ents.Create( "point_hurt" )
		b:SetKeyValue("targetname", "fire" ) 
		b:SetKeyValue("DamageRadius", "500" )
		b:SetKeyValue("Damage", tostring(dam))
		b:SetKeyValue("DamageDelay", "7" )
		b:SetKeyValue("DamageType", "262144" )
		b:SetPos(self.Entity:GetPos()+Vector(0,0,15))
		b:Spawn()
		b:Fire("turnon", "", 0)
		b:Fire("turnoff", "", 1)
		b:Fire("kill", "", 1)
		self.incrad = false
	else
		local dam = math.random(1,5)
		local b = ents.Create( "point_hurt" )
		b:SetKeyValue("targetname", "fire" ) 
		b:SetKeyValue("DamageRadius", "250" )
		b:SetKeyValue("Damage", tostring(dam))
		b:SetKeyValue("DamageDelay", "7" )
		b:SetKeyValue("DamageType", "262144" )
		b:SetPos( self.Entity:GetPos()+Vector(0,0,15))
		b:Spawn()
		b:Fire("turnon", "", 0)
		b:Fire("turnoff", "", 1)
		b:Fire("kill", "", 1)
	end
end

function ENT:Touch(activator)
	local pos = self.Entity:GetPos()
	local speed = self.Entity:GetVelocity():Length()
	local totalspeed = ((activator:GetVelocity():Length()) + speed)
	if activator:GetClass() == "sent_subcriticalmass" or activator:GetClass() == "sent_uraniumresource" then
		if totalspeed >= 1250 then
			util.BlastDamage(self.Entity, self.Entity, self.Entity:GetPos(), 256, 512)
			local Effect = EffectData()
				Effect:SetOrigin(self.Entity:GetPos())
				Effect:SetScale(10)
				Effect:SetMagnitude(100)
			util.Effect("Explosion", Effect, true, true)
			self.Entity:Remove()
			activator:Remove()
		elseif totalspeed >= 200 then
			local effectdata = EffectData()
				effectdata:SetOrigin(pos)
				effectdata:SetEntity(self.Entity)
			util.Effect("ManhackSparks", effectdata)
			self.incrad = true
			
		end
	end
end